/*
 * 
*/ 

// Version_test.h contains definitions for to_string and stod
// if the compiler does not yet define these functions,
// this code will use the definitions we provide
#include "Version_test.h" 

#include <string>
using std::string;
#ifdef STRING_NUMERIC_CONVS
using std::to_string; using std::stod;
#endif

#include <iostream>
using std::cout; using std::endl;

int main()
{
	/*
	新标准引入了多个函数,可以实现数值数据与标准库string之间的转换
	*/
	int i = 42;
	// 将整数i转换为字符表示形式
	string s = to_string(i);  

	double d = stod(s);   // 将字符串s转化为浮点数
	cout << "i = " << i << " s = " << s << " d is: " << d << endl;

	// 转换s中以数字开始的第一个子串,结果d=3.14
	string s2 = "pi = 3.14";
	d = stod(s2.substr(s2.find_first_of("+-.0123456789")));

	cout << "d = " << d << " s = " << s << " s2 is: " << s2 << endl;

	return 0;
}
